package com.hzgj.bcl.redis;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Hash {
    final static ThreadLocal<MessageDigest> md5Holder = ThreadLocal.withInitial(() -> {
        try {
            return MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("MD5 Algorithm is not found");
        }
    });
    final static MD5Hash Instance = new MD5Hash();

    private MD5Hash() {
    }

    public byte[] hash(byte[] key) {
        MessageDigest md5 = md5Holder.get();

        md5.reset();
        md5.update(key);
        return  md5.digest();
    }

}